package com.yx.feign.consume.client;


import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "springboot-feign-produce" ,fallbackFactory = TestFeignFallbackFactory.class)
public interface TestFeignClient {

    @RequestMapping("/feign-produce/test/hello")
    String produce(@RequestParam String name);
}

@Component
class TestFeignFallbackFactory implements FallbackFactory<TestFeignClient> {

    @Override
    public TestFeignClient create(Throwable throwable) {
        System.out.println("调用服务失败熔断");
        return new TestFeignClient(){
            @Override
            public String produce(String name) {
                return "ERROR:FEIGN";
            }
        };
    }
}
